<?php
namespace app\bbs\controller;
use x\Xbase;
use ETaobao\Factory;
class Myg extends Base{

  public function t(){
      $config = [
          'appkey' => '23545895',
          'secretKey' => '07831869794dba604792dd4b297be9f9',
          'format' => 'json',
          'sandbox' => false,
      ];
      $app = Factory::Tbk($config);
      // $param = [
      //    'fields' => "favorites_title,favorites_id,type",
      //    'page_size'=>15,
      //    'page_no'=>1,
      // ];
      // $res = $app->uatm->getFavorites($param);
      // t($res);
      // $param = [
      //    'fields' => "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,status,type",
      //    "adzone_id"=>1374690897,
      //    "favorites_id"=>17989206,
      //    'page_size'=>15,
      //    'page_no'=>1,
      // ];
      // $res = $app->uatm->getItemFavorites($param);
      // t($res);

      $param = [
         //'fields' => "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,status,type",
         "adzone_id"=>1374690897,
         // "favorites_id"=>17989206,
         "q"=>"内裤",
         'page_size'=>15,
         'page_no'=>1,
      ];
      $res = $app->dg->getCoupon($param);
      t($res);

  }
  //蚂蚁购首页
  public function index(){
    if(is_post()){
      $d = $this->post();
      $config = [
          'appkey' => '23545895',
          'secretKey' => '07831869794dba604792dd4b297be9f9',
          'format' => 'json',
          'sandbox' => false,
      ];
      $app = Factory::Tbk($config);
      $param = [
         'fields' => "title, pict_url,reserve_price,zk_final_price,item_url,volume",
         "q"=>$this->post('q','女装'),
         "start_tk_rate"=>$this->post('start_tk_rate',0),
         "end_tk_rate"=>$this->post('end_tk_rate',100),
         "start_price"=>$this->post('start_price',0),
         "end_price"=>$this->post('end_price',20000),
         "is_tmall"=>$this->post('is_tmall',0)?"true":false,
         "is_overseas"=>$this->post('is_overseas',0)?"true":false,
         "sort"=>$this->post('sort','tk_total_sales_desc'),
         'page_size'=>15,
         'page_no'=>$d['page'],
      ];
      $res = $app->item->get($param);
      $res = json_encode($res);
      $res = json_decode($res,true);
      if(!isset($res['total_results'])){
        err($res['msg']);
      }
      $page = floor($res['total_results']/15);
      $res = isset($res['results']['n_tbk_item'])?$res['results']['n_tbk_item']:[];

      $html = '';
      foreach($res as $v){
        $zk = $v['reserve_price']-$v['zk_final_price'];
        $html .='<li>
                <a href="'.$v['item_url'].'" target="_blank">
                  <div>
                      <div class="autoimg">
                        <img lay-src="'.$v['pict_url'].'" align="absmiddle">
                      </div>
                      <p class="title">'.$v['title'].'</p>
                      <div class="layui-row fs18 mt10">
                        <div class="layui-col-lg6 red quanhou">折后价￥<span class="fs20">'.$v['zk_final_price'].'</span></div>
                        <div class="layui-col-lg6 xiaoliang fs18">销量'.$v['volume'].'</div>
                      </div>
                  </div>
                </a>
              </li>';
      }
      suc(['html'=>$html,'page'=>$page]);
    }
    $d = [
      "q"=>$this->get('q','女装'),
      "start_tk_rate"=>$this->get('start_tk_rate',0),
      "end_tk_rate"=>$this->get('end_tk_rate',100),
      "start_price"=>$this->get('start_price',0),
      "end_price"=>$this->get('end_price',20000),
      "sort"=>$this->get('sort','tk_total_sales_desc'),
      "is_tmall"=>$this->get('is_tmall',0),
      "is_overseas"=>$this->get('is_overseas',0),
    ];
    $this->fetch($d);
  }
}
